<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>关键词配置管理</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
        }
        .actions {
            text-align: center;
            margin-bottom: 20px;
        }
        .btn {
            display: inline-block;
            padding: 10px 20px;
            margin: 5px;
            background-color: #007bff;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            border: none;
            cursor: pointer;
        }
        .btn:hover {
            background-color: #0056b3;
        }
        .btn-danger {
            background-color: #dc3545;
        }
        .btn-danger:hover {
            background-color: #c82333;
        }
        .btn-success {
            background-color: #28a745;
        }
        .btn-success:hover {
            background-color: #218838;
        }
        .btn-warning {
            background-color: #ffc107;
            color: #212529;
        }
        .btn-warning:hover {
            background-color: #e0a800;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f8f9fa;
            font-weight: bold;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
        .status-enabled {
            color: #28a745;
            font-weight: bold;
        }
        .status-disabled {
            color: #dc3545;
            font-weight: bold;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        .form-group input, .form-group select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
        }
        .modal-content {
            background-color: white;
            margin: 10% auto;
            padding: 20px;
            border-radius: 8px;
            width: 50%;
            box-shadow: 0 4px 20px rgba(0,0,0,0.3);
        }
        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
            cursor: pointer;
        }
        .close:hover {
            color: black;
        }
        .message {
            padding: 10px;
            margin: 10px 0;
            border-radius: 4px;
        }
        .message.success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .message.error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>关键词配置管理</h1>
        
        <div class="actions">
            <a href="/keyword-configs/add" class="btn">添加关键词配置</a>
            <a href="/" class="btn btn-secondary">返回主页</a>
        </div>
        
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="message {{ category }}">{{ message }}</div>
                {% endfor %}
            {% endif %}
        {% endwith %}
        
        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>关键词</th>
                    <th>数量</th>
                    <th>平台</th>
                    <th>原语言</th>
                    <th>目标语言</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>上次运行时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for config in configs %}
                <tr>
                    <td>{{ config.id }}</td>
                    <td>{{ config.keyword }}</td>
                    <td>{{ config.count }}</td>
                    <td>
                        {% if config.platform == 'douyin' %}抖音
                        {% else %}{{ config.platform }}
                        {% endif %}
                    </td>
                    <td>
                        {% if config.source_lang == 'en' %}英语
                        {% elif config.source_lang == 'zh' %}中文
                        {% elif config.source_lang == 'th' %}泰语
                        {% elif config.source_lang == 'vi' %}越南语
                        {% else %}{{ config.source_lang }}
                        {% endif %}
                    </td>
                    <td>
                        {% if config.target_lang == 'vi' %}越南语
                        {% elif config.target_lang == 'th' %}泰语
                        {% elif config.target_lang == 'pt-br' %}葡萄牙语-巴西
                        {% else %}{{ config.target_lang }}
                        {% endif %}
                    </td>
                    <td>
                        {% if config.enabled %}
                            <span class="status-enabled">启用</span>
                        {% else %}
                            <span class="status-disabled">禁用</span>
                        {% endif %}
                    </td>
                    <td>{{ config.create_time }}</td>
                    <td>{{ config.last_run_time or '从未运行' }}</td>
                    <td>
                        {% if config.enabled %}
                            <form action="/keyword-configs/trigger/{{ config.id }}" method="post" style="display: inline;">
                                <button type="submit" class="btn btn-warning" onclick="return confirm('确定要立即执行这个任务吗？')">立即执行</button>
                            </form>
                        {% endif %}
                        <a href="/keyword-configs/edit/{{ config.id }}" class="btn">编辑</a>
                        <form action="/keyword-configs/delete/{{ config.id }}" method="post" style="display: inline;">
                            <button type="submit" class="btn btn-danger" onclick="return confirm('确定要删除这个配置吗？')">删除</button>
                        </form>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</body>
</html>